package com.music.action.authority;

import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.music.action.BaseAction;
import com.music.authority.service.AuthorityService;
import com.music.common.ParamUtil;

/**
 * 注册页面action
 * @author LFSenior
 *
 */
public class SignUpAction extends BaseAction{
	@Autowired
	AuthorityService authorityService;
	/**
	 * 跳转到登录界面
	 * @return
	 */
	@Action(value="signup",results={@Result(name="signup",location="core/signup.jsp")})
	public String redicterSignUp(){
		return "signup";
	}
	
	/**
	 * 注册方法
	 * @return
	 */
	@Action(value="register",results={@Result(name="register",type="json",params={"root","reParam"})})
	public String register(){
		try {
			Map<String, Object> param = ParamUtil.buildRequest(ServletActionContext.getRequest());
			//添加用户id字段
			param.put("id", ParamUtil.buildUUID());
			authorityService.insertUser(param);
			reParam.put("result", "T");
		} catch (Exception e) {
			reParam.put("result", "F");
		}
		return "register";
	}
}
